// (C) Copyright 2006 Marvell International Ltd.
// All Rights Reserved
//

#include <windows.h>
#include "display_ipm.h"
#include "gcu.h"

extern void gcu_notify_proc_state(DWORD state);
extern "C" volatile XLLP_CLKMGR_T* v_pClkRegs;

void GCU::init_power()
{
    InitClkMgr(CLKMGR_SIDECAR, &clk_mgr);
}

void GCU::request_clock(bool is_on)
{
    if (is_on)
        EnableClock(&clk_mgr);
    else
        DisableClock(&clk_mgr);


    XllpClockEnable((P_XLLP_CLKMGR_T)v_pClkRegs, XLLP_CLK_HSIO_GCU, is_on? XLLP_TRUE : XLLP_FALSE);
}

void GCU::set_power_mode(bool is_on)
{
    request_clock(is_on);
    clock_state = is_on;

#if 0
    DWORD state = IPM_PROCESSOR_D0_RDY | IPM_PROCESSOR_RING_OSC_RDY;

    if (!is_on)
        state |= IPM_PROCESSOR_D1_RDY | IPM_PROCESSOR_D2_RDY;

    ipm_client->gcu_notify_proc_state(state); 
#endif
}

void GCU::suspend()
{
    NKDbgPrintfW(TEXT("gcu suspend!\r\n"));

    need_reset = 1;
    context = 0;

    if (!clock_state)
        return;

    const UINT max_wait = 10000;

    for (UINT i = 0; i < max_wait; i++)
    {
        if (regs->gcrbexhr == regs->gcrbtr)
            return;
    }

    NKDbgPrintfW(TEXT("gcu suspend sync timeout!\r\n"));
}


void GCU::resume()
{
}